
What is Javascript ?
Jaascript is client side scripting language, which is used to communicate with HTML elements(DOM Nodes).

Javascript is executed by browser.(Browser also handles cookie)
-------------------------
How to Write Javascript on WebPage ?
a) On Page JS
<script type="text/javascript">
  // JS code goes here
</script>
b) Off Page JS
  (Include external JS)
<script src="js/register.js" type="text/javascript"></script>
c) In Line JS
  (We can use InLine JS in form of events)
  <input type="text" name="" onClick="javascript:alert('Hello')" />
--------------------------
How to take variable in JS ?
"var" keyword is used to take varibale.For Ex:
var num = 121;
--------------------------
Ways to show output on browser with JS ?

1 ) alert("I am alert");
2 ) confirm ("Are you sure , you want to delete ?");
<script type="text/javascript">

var returnValue = confirm('Are you sure to delete ?');
alert(returnValue);
if(returnValue == true){
  alert("Delete this user.");
} else {
  alert("Don't delete this user.");
}
</script>

3) document.write("I am written by JS.");
4) console.log("You can check this message in Firebug's console.Press F12 to open firebug.");
--------------------------
Comment is JS :

JS Follow C style comment.

// Single line comment

/*
* Multi line comment
*/

--------------------------
Common rules which we Should follow while writing JS.
1) SemiColon is optional at end of statement.But for better programming practice try to keep it.

2) Always try to use multi line comment even you have to comment single line.Because in future version of your JS file, your JS file will be compressed.

And in Compressed file all the code gone into single line.And we know single line will comment complete line.Because single line comment don't have it's end mark.

3) Always use var before defining varibale.

4) For equality(==) try to use identical (===) operator.

--------------------------
Datatypes in JS :
Javascript automatically assign datatype of varibale according to varibale's value.

1) number
2) string
3) array
4) object
5) undefined
6) boolean

-------------------------
How to detect datatype of varibale ?

use "typeof" before  varibale.
var num = 123;
alert(typeof num);//number
-----------------------
How to concatenate two variable or string in JS?
Use PLUS(+) as concatenation operator.
for ex :
alert("Hello "+" World")
-------------------------
_______STRING________
1) LENGTH
var str = "Hello JS";
alert(str.length);
2) STRING REPLACE
<script type="text/javascript">

var str = "Hello JS,Bye JS";
var newstr = str.replace('JS','World!!')
alert(newstr);// WOW!! JS

</script>
3) STRING REPLACE ALL OCCURANCE
<script type="text/javascript">

var str = "Hello JS,Bye JS";
var newstr = str.replace(/JS/g,'World!!')
alert(newstr);// WOW!! JS

</script>
4) Check Existance Of character in String
<script type="text/javascript">

var str = "Hello JS,Bye JS";
var pos = str.indexOf('JS');
alert(pos);// WOW!! JS

</script>

 Note : if character don't exists in string then we will get return "-1"

 There is another function "lastIndexOf()"
-------------------------
Type Casting in JS.
<script type="text/javascript">

var str = '123hello';
    str = parseInt(str);
alert(typeof str);
alert(str);

</script>
<script type="text/javascript">

var str = '123.345hello';
    str = parseFloat(str);
alert(typeof str);
alert(str);

</script>
<script type="text/javascript">

var str = 123.3456789;
    str = str.toString();
alert(typeof str);
alert(str);

</script>

--------------------------
Fix Decimal palces in Float Numbers.
<script type="text/javascript">

var str = 123.3456789;
    str = str.toFixed(2);
alert(str);

</script>
--------------------------

--------------------------
What is DOM ?
D (Document)
O (Object)
M (Model)
DOM is commonly known as "document" Object , which is predefine in JS.Document object hold complete detail of visible area of browser.

"DOM" is TREE like structure contain nodes and elements.
<ul>
  <li><input type="text" name="" value="" id="" />
  </li>
</ul>

* <ul> and <li> are nodes
* <input> is element

When Web page loads then all elements register themselves in DOM.
-----------------------
How to change URL with JS?
window.location = "http://google.com";
---------------------
How to perform any operation with delay of 1 sec.
<script type="text/javascript">
setTimeout(function(){alert('Hi')},2000);
</script>
---------------------
--------:ARRAY :-----

<script type="text/javascript">

var arr = ['one','two','three','four'];
console.log(arr);
var str = arr.join('#');
console.log(str);
var reArray = str.split("#");
console.log(reArray);
</script>
------------------------
Events :
1.onClick()
2.onBlur()
3.onChange()
4.onSubmit()
------------------------
<input type="text"
       name="uname"
       value="Rasmus"
       onClick="alert(this.value)" />
In above code "this" is current object which is referred as <input> for above.
"this" has all the details of <input> means it knows it's name , it's value, it's id,placeholder etc..

So,If you want to access id attribute of <input> then you have to write

"this.id" for Id
"this.name" for Name
"this.placeholder" for Placeholder

------------------------
<input type = "text"
       name = "email"
       onBlur ="alert(this.value)" />
-----------------------



